package sort;

/**
 * @author LQQ
 * @version V1.0
 * @Package PACKAGE_NAME
 * @date 2020/10/11 17:04
 * @Description
 */
public class ShellSort {
    public static int[] shellSort(int[] array) {
        int len = array.length;
        int temp, gap = len / 2;
        while (gap > 0) {
            for (int i = gap; i < len; i++) {
                temp = array[i];
                int preIndex = i - gap;
                while (preIndex >= 0 && array[preIndex] > temp) {
                    array[preIndex + gap] = array[preIndex];
                    preIndex -= gap;
                }
                array[preIndex + gap] = temp;
            }
            gap /= 2;
        }
        return array;
    }

    public static void main(String[] args) {
        int[] array = new int[]{11, 1, 3, 1, 4, 7, 45, 76, 23, 7, 34, 9, 90, 0};
        array = shellSort(array);
        for (int num : array) {
            System.out.println(num);
        }
    }

}
